package com.java1412;

/**
 * @author java1412
 * @create 2022-09-21 15:28
 */
public class Test1 {
    public static void main(String[] args) {
        ClimbThread t1 = new ClimbThread("年轻人", 350, 20);
        ClimbThread t2 = new ClimbThread("老年人", 500, 10);
        t1.start();
        t2.start();
    }
}

class ClimbThread extends Thread {

    private int time;
    private int num;

    public ClimbThread(String name, int time, int num) {
        super(name);
        this.time = time;
        this.num = num;
    }

    @Override
    public void run() {
        while (true) {
            if (num < 1) {
                break;
            }
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            num--;
            System.out.println(Thread.currentThread().getName() + "爬完100米!");
        }
        System.out.println(Thread.currentThread().getName() + "到达终点!");
    }
}
